package com.tanhua.dubbo.api.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.domain.db.User;
import com.tanhua.dubbo.api.UserApi;
import com.tanhua.dubbo.mapper.UserMapper;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
public class UserApiImpl implements UserApi {

    @Autowired
    private UserMapper userMapper;


    /**
     * 作用：保存用户
     * @param user
     * @return
     */
    @Override
    public long save(User user) {
        userMapper.insert(user);
        return user.getId();
    }

    /**
     * 根据手机号查找用户
     * @param mobile
     * @return
     */
    @Override
    public User findByMobile(String mobile) {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("mobile",mobile);
        User user = userMapper.selectOne(queryWrapper);
        return user;
    }

    @Override
    public List<User> findAll() {
        List<User> userList = userMapper.selectList(null);
        return userList;
    }

    @Override
    public void update(User updateUser) {
        userMapper.updateById(updateUser);
    }
    /**
     * 更新用户的手机号
     *
     * @param user
     */
    @Override
    public void upDataPhone(User user) {
        userMapper.updateById(user);
    }
}
